<?php
namespace app\service;


use app\model\PilotListModel;

class PilotService
{
    private $arr=[];
    public function tree(){
        $this->arr=[];
        $res = PilotListModel::alias('pl')
            ->Join('pilot_nav pn','pl.pn_id = pn.id','left')
            ->field('pl.*,pn.name as pname')
            ->order('pl.sort ASC')->select();
        return $this->sort($res);
    }
    protected function sort($res,$fid=0,$level=0){
        foreach ($res as $key => $value) {
            if($value['fid']==$fid){
                $value['level']=$level;
                $this->arr[]=$value;
                $this->sort($res,$value['id'],$level+1);
            }
        }
        return $this->arr;
    }
}